package com.kaishengit.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.dao.UserDao;
import com.kaishengit.pojo.User;

@Service
@Transactional
public class UserService {

	private UserDao userDao;

	public void save(User user) {
		user.setNickname("null");
		user.setImg(null);
		userDao.save(user);
	}
	
	public void update(User user) {
		userDao.update(user);
	}
	
	public void del(int id) {
		userDao.del(id);
	}
	
	@Transactional(readOnly=true)
	public User findById(int id) {
		return userDao.findById(id);
	}
	
	@Transactional(readOnly=true)
	public User findByNameAndPwd(User user){
		return userDao.findNameAndPassword(user);
	}
	
	@Transactional(readOnly=true)
	public List<User> findAll() {
		return userDao.findAll();
	}
	
	@Autowired
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public User findByName(String name) {
		return userDao.findByName(name);
	}

}
